package com.zhuzhe.blog.question.api;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zhuzhe.blog.base.BaseRequest;
import com.zhuzhe.blog.base.ResponseData;
import com.zhuzhe.blog.question.entity.Question;
import com.zhuzhe.blog.question.responseVo.QuestionPageVo;
import com.zhuzhe.blog.question.responseVo.QuestionVo;
import com.zhuzhe.blog.question.service.IQuestionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@Api(value = "问答管理接口", description = "问答管理接口,不用通过身份认证即可调用接口")
@RestController
@RequestMapping("/api/question")
public class ApiQuestionController {

    @Autowired
    private IQuestionService questionService;

    @ApiOperation("分页查询热门问答列表接口")
    @PostMapping("/hot") // localhost:8002/question/api/question/hot
    public ResponseData<IPage<QuestionPageVo>> findHotList(@RequestBody BaseRequest<Question> baseRequestDto) {
        return questionService.findHotList(baseRequestDto);
    }

    @ApiOperation("分页查询最新问答列表接口")
    @PostMapping("/new")
    public ResponseData<IPage<QuestionPageVo>> findNewList(@RequestBody BaseRequest<Question> req) {
        return questionService.findNewList(req);
    }

    @ApiOperation("分页查询等待回答列表接口")
    @PostMapping("/wait")
    public ResponseData<IPage<QuestionPageVo>> findWaitList(@RequestBody BaseRequest<Question> req) {
        return questionService.findWaitList(req);
    }

    @ApiImplicitParam(name="labelId", value="标签ID", required=true)
    @ApiOperation("根据标签ID分页查询问答列表接口")
    @PostMapping("/list/{labelId}")
    public ResponseData<IPage<QuestionPageVo>> findListByLabelId(@RequestBody BaseRequest<Question> baseRequest,
                                    @PathVariable("labelId") String labelId) {
        return questionService.findListByLabelId(baseRequest, labelId);
    }

    @ApiOperation("查询问题详情接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "问题id" ,required = true),
            @ApiImplicitParam(name = "userId",value = "用户id" ,required = false)
    })
    @GetMapping("/{id}")
    public ResponseData<QuestionVo> view(@PathVariable("id") String id ,
                                         String userId) {
       return questionService.findById(id,userId);
    }


    @ApiOperation("更新浏览数接口")
    @ApiImplicitParam(name="id", value="问题ID", required=true)
    @PutMapping("/viewCount/{id}")
    public ResponseData<String> updateViewCount(@PathVariable("id") String id,HttpServletRequest request) {
        return questionService.updateViewCount(id,request);
    }

}
